import java.io.*;
import javax.swing.JOptionPane;
import java.lang.reflect.Array;
/**
 *
 * @author  tim
 */
public class Main extends javax.swing.JFrame
{
     private String text;
     private File file;
     private File assembledFile;
     
     private Assembled aObject;
     
     private Simulator simulator;
     /** Creates new form Main */
     public Main()
     {
	  initComponents();
     }
     
     /** This method is called from within the constructor to
      * initialize the form.
      * WARNING: Do NOT modify this code. The content of this method is
      * always regenerated by the Form Editor.
      */
     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
     private void initComponents()
     {

          fileChooser = new javax.swing.JFileChooser();
          jOptionPane1 = new javax.swing.JOptionPane();
          jSeparator1 = new javax.swing.JSeparator();
          openButton = new javax.swing.JButton();
          saveButton = new javax.swing.JButton();
          jTabbedPane1 = new javax.swing.JTabbedPane();
          EditorPane = new javax.swing.JPanel();
          jScrollPane1 = new javax.swing.JScrollPane();
          editor = new javax.swing.JEditorPane();
          AssemblerPane = new javax.swing.JPanel();
          assembleButton = new javax.swing.JButton();
          jScrollPane3 = new javax.swing.JScrollPane();
          errorPane = new javax.swing.JTextArea();
          SimulatorPane = new javax.swing.JPanel();
          jScrollPane2 = new javax.swing.JScrollPane();
          outputWindow = new javax.swing.JTextArea();
          jPanel1 = new javax.swing.JPanel();
          r0 = new javax.swing.JTextField();
          r1 = new javax.swing.JTextField();
          r2 = new javax.swing.JTextField();
          r3 = new javax.swing.JTextField();
          r4 = new javax.swing.JTextField();
          r5 = new javax.swing.JTextField();
          r6 = new javax.swing.JTextField();
          jLabel2 = new javax.swing.JLabel();
          jLabel3 = new javax.swing.JLabel();
          jLabel4 = new javax.swing.JLabel();
          jLabel5 = new javax.swing.JLabel();
          jLabel6 = new javax.swing.JLabel();
          jLabel7 = new javax.swing.JLabel();
          jLabel8 = new javax.swing.JLabel();
          jPanel2 = new javax.swing.JPanel();
          r7 = new javax.swing.JTextField();
          r8 = new javax.swing.JTextField();
          r9 = new javax.swing.JTextField();
          r10 = new javax.swing.JTextField();
          r11 = new javax.swing.JTextField();
          r12 = new javax.swing.JTextField();
          r13 = new javax.swing.JTextField();
          jLabel9 = new javax.swing.JLabel();
          jLabel10 = new javax.swing.JLabel();
          jLabel11 = new javax.swing.JLabel();
          jLabel12 = new javax.swing.JLabel();
          jLabel13 = new javax.swing.JLabel();
          jLabel14 = new javax.swing.JLabel();
          jLabel15 = new javax.swing.JLabel();
          jPanel3 = new javax.swing.JPanel();
          r14 = new javax.swing.JTextField();
          r15 = new javax.swing.JTextField();
          r16 = new javax.swing.JTextField();
          r17 = new javax.swing.JTextField();
          r18 = new javax.swing.JTextField();
          r19 = new javax.swing.JTextField();
          r20 = new javax.swing.JTextField();
          jLabel16 = new javax.swing.JLabel();
          jLabel17 = new javax.swing.JLabel();
          jLabel18 = new javax.swing.JLabel();
          jLabel19 = new javax.swing.JLabel();
          jLabel20 = new javax.swing.JLabel();
          jLabel21 = new javax.swing.JLabel();
          jLabel22 = new javax.swing.JLabel();
          jPanel4 = new javax.swing.JPanel();
          r21 = new javax.swing.JTextField();
          r22 = new javax.swing.JTextField();
          r23 = new javax.swing.JTextField();
          r24 = new javax.swing.JTextField();
          r25 = new javax.swing.JTextField();
          r26 = new javax.swing.JTextField();
          r27 = new javax.swing.JTextField();
          jLabel23 = new javax.swing.JLabel();
          jLabel24 = new javax.swing.JLabel();
          jLabel25 = new javax.swing.JLabel();
          jLabel26 = new javax.swing.JLabel();
          jLabel27 = new javax.swing.JLabel();
          jLabel28 = new javax.swing.JLabel();
          jLabel29 = new javax.swing.JLabel();
          jPanel5 = new javax.swing.JPanel();
          r28 = new javax.swing.JTextField();
          r29 = new javax.swing.JTextField();
          r30 = new javax.swing.JTextField();
          r31 = new javax.swing.JTextField();
          jLabel30 = new javax.swing.JLabel();
          jLabel31 = new javax.swing.JLabel();
          jLabel32 = new javax.swing.JLabel();
          jLabel33 = new javax.swing.JLabel();
          r32 = new javax.swing.JTextField();
          jLabel35 = new javax.swing.JLabel();
          lineNumberLabel = new javax.swing.JTextField();
          jLabel36 = new javax.swing.JLabel();
          jPanel6 = new javax.swing.JPanel();
          fullExecute = new javax.swing.JButton();
          singleLineExecute = new javax.swing.JButton();
          reset = new javax.swing.JButton();
          loadObjectFile = new javax.swing.JButton();
          saveObjectFile = new javax.swing.JButton();
          jSeparator2 = new javax.swing.JSeparator();
          jMenuBar1 = new javax.swing.JMenuBar();
          jMenu1 = new javax.swing.JMenu();
          menuOpen = new javax.swing.JMenuItem();
          menuSave = new javax.swing.JMenuItem();

          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
          setTitle("Full Mips Simulator Version 2 Final");

          openButton.setText("Open");
          openButton.addMouseListener(new java.awt.event.MouseAdapter()
          {
               public void mousePressed(java.awt.event.MouseEvent evt)
               {
                    openButtonMousePressed(evt);
               }
          });
          openButton.addActionListener(new java.awt.event.ActionListener()
          {
               public void actionPerformed(java.awt.event.ActionEvent evt)
               {
                    openButtonActionPerformed(evt);
               }
          });

          saveButton.setText("Save");
          saveButton.addMouseListener(new java.awt.event.MouseAdapter()
          {
               public void mousePressed(java.awt.event.MouseEvent evt)
               {
                    saveButtonMousePressed(evt);
               }
          });

          jScrollPane1.setViewportView(editor);

          javax.swing.GroupLayout EditorPaneLayout = new javax.swing.GroupLayout(EditorPane);
          EditorPane.setLayout(EditorPaneLayout);
          EditorPaneLayout.setHorizontalGroup(
               EditorPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE)
          );
          EditorPaneLayout.setVerticalGroup(
               EditorPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
          );

          jTabbedPane1.addTab("Editor", EditorPane);

          assembleButton.setText("Assemble");
          assembleButton.addMouseListener(new java.awt.event.MouseAdapter()
          {
               public void mousePressed(java.awt.event.MouseEvent evt)
               {
                    assembleButtonMousePressed(evt);
               }
          });

          errorPane.setColumns(20);
          errorPane.setRows(5);
          jScrollPane3.setViewportView(errorPane);

          javax.swing.GroupLayout AssemblerPaneLayout = new javax.swing.GroupLayout(AssemblerPane);
          AssemblerPane.setLayout(AssemblerPaneLayout);
          AssemblerPaneLayout.setHorizontalGroup(
               AssemblerPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(AssemblerPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(AssemblerPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                         .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 715, Short.MAX_VALUE)
                         .addComponent(assembleButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 715, Short.MAX_VALUE))
                    .addContainerGap())
          );
          AssemblerPaneLayout.setVerticalGroup(
               AssemblerPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(AssemblerPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(assembleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                    .addContainerGap())
          );

          jTabbedPane1.addTab("Assembler", AssemblerPane);

          outputWindow.setColumns(20);
          outputWindow.setEditable(false);
          outputWindow.setRows(5);
          jScrollPane2.setViewportView(outputWindow);

          r0.setText("0");

          r1.setText("0");

          r2.setText("0");

          r3.setText("0");

          r4.setText("0");
          r4.addActionListener(new java.awt.event.ActionListener()
          {
               public void actionPerformed(java.awt.event.ActionEvent evt)
               {
                    r4ActionPerformed(evt);
               }
          });

          r5.setText("0");

          r6.setText("0");

          jLabel2.setText("$zero");

          jLabel3.setText("$at");

          jLabel4.setText("$v0");

          jLabel5.setText("$v1");

          jLabel6.setText("$a0");

          jLabel7.setText("$a1");

          jLabel8.setText("$a2");

          javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
          jPanel1.setLayout(jPanel1Layout);
          jPanel1Layout.setHorizontalGroup(
               jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(jLabel2)
                         .addComponent(jLabel3)
                         .addComponent(jLabel4)
                         .addComponent(jLabel5)
                         .addComponent(jLabel6)
                         .addComponent(jLabel7)
                         .addComponent(jLabel8))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                         .addComponent(r6, javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(r5, javax.swing.GroupLayout.Alignment.TRAILING, 0, 0, Short.MAX_VALUE)
                         .addComponent(r4, javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(r3, javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(r2, javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(r1, javax.swing.GroupLayout.Alignment.TRAILING, 0, 0, Short.MAX_VALUE)
                         .addComponent(r0, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE))
                    .addContainerGap())
          );
          jPanel1Layout.setVerticalGroup(
               jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel2))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel3))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel4))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel5))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel6))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel7))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel8)))
          );

          r7.setText("0");
          r7.addActionListener(new java.awt.event.ActionListener()
          {
               public void actionPerformed(java.awt.event.ActionEvent evt)
               {
                    r7ActionPerformed(evt);
               }
          });

          r8.setText("0");

          r9.setText("0");

          r10.setText("0");

          r11.setText("0");

          r12.setText("0");

          r13.setText("0");

          jLabel9.setText("$a3");

          jLabel10.setText("$t0");

          jLabel11.setText("$t1");

          jLabel12.setText("$t2");

          jLabel13.setText("$t3");

          jLabel14.setText("$t4");

          jLabel15.setText("$t5");

          javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
          jPanel2.setLayout(jPanel2Layout);
          jPanel2Layout.setHorizontalGroup(
               jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                    .addContainerGap(39, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(jLabel9)
                         .addComponent(jLabel10)
                         .addComponent(jLabel12)
                         .addComponent(jLabel13)
                         .addComponent(jLabel14)
                         .addComponent(jLabel15)
                         .addComponent(jLabel11))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                         .addComponent(r13, javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(r12, javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(r11, javax.swing.GroupLayout.Alignment.TRAILING, 0, 0, Short.MAX_VALUE)
                         .addComponent(r10, javax.swing.GroupLayout.Alignment.TRAILING, 0, 0, Short.MAX_VALUE)
                         .addComponent(r9, javax.swing.GroupLayout.Alignment.TRAILING, 0, 0, Short.MAX_VALUE)
                         .addComponent(r8, javax.swing.GroupLayout.Alignment.TRAILING, 0, 0, Short.MAX_VALUE)
                         .addComponent(r7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE))
                    .addContainerGap())
          );
          jPanel2Layout.setVerticalGroup(
               jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel9))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel10))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel11))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel12))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel13))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel14))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel15))
                    .addContainerGap(70, Short.MAX_VALUE))
          );

          r14.setText("0    ");
          r14.addActionListener(new java.awt.event.ActionListener()
          {
               public void actionPerformed(java.awt.event.ActionEvent evt)
               {
                    r14ActionPerformed(evt);
               }
          });

          r15.setText("0");

          r16.setText("0");

          r17.setText("0");

          r18.setText("0");

          r19.setText("0");

          r20.setText("0     ");

          jLabel16.setText("$t6");

          jLabel17.setText("$t7");

          jLabel18.setText("$s0");

          jLabel19.setText("$s1");

          jLabel20.setText("$s2");

          jLabel21.setText("$s3");

          jLabel22.setText("$s4");

          javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
          jPanel3.setLayout(jPanel3Layout);
          jPanel3Layout.setHorizontalGroup(
               jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGap(29, 29, 29)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                         .addGroup(jPanel3Layout.createSequentialGroup()
                              .addComponent(jLabel22)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(r20, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE))
                         .addGroup(jPanel3Layout.createSequentialGroup()
                              .addComponent(jLabel21)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(r19, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE))
                         .addGroup(jPanel3Layout.createSequentialGroup()
                              .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel16)
                                   .addComponent(jLabel17)
                                   .addComponent(jLabel18)
                                   .addComponent(jLabel19)
                                   .addComponent(jLabel20))
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                   .addComponent(r18)
                                   .addComponent(r17)
                                   .addComponent(r16)
                                   .addComponent(r15)
                                   .addComponent(r14, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))))
                    .addContainerGap())
          );
          jPanel3Layout.setVerticalGroup(
               jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(jLabel16)
                         .addComponent(r14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(jLabel17)
                         .addComponent(r15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(jLabel18)
                         .addComponent(r16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(jLabel19)
                         .addComponent(r17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(jLabel20)
                         .addComponent(r18, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(jLabel21)
                         .addComponent(r19, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(jLabel22)
                         .addComponent(r20, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(70, 70, 70))
          );

          r21.setText("0");

          r22.setText("0");

          r23.setText("0");

          r24.setText("0");

          r25.setText("0");

          r26.setText("0");

          r27.setText("0");

          jLabel23.setText("$s6");

          jLabel24.setText("$s6");

          jLabel25.setText("$s7");

          jLabel26.setText("$t8");

          jLabel27.setText("$t9");

          jLabel28.setText("$k0");

          jLabel29.setText("$k1");

          javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
          jPanel4.setLayout(jPanel4Layout);
          jPanel4Layout.setHorizontalGroup(
               jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                    .addContainerGap(46, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(jLabel23)
                         .addComponent(jLabel24)
                         .addComponent(jLabel25)
                         .addComponent(jLabel26)
                         .addComponent(jLabel27)
                         .addComponent(jLabel28)
                         .addComponent(jLabel29))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                         .addComponent(r27)
                         .addComponent(r25, javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(r24, javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(r23, javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(r22, javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(r21, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)
                         .addComponent(r26, javax.swing.GroupLayout.Alignment.TRAILING, 0, 0, Short.MAX_VALUE)))
          );
          jPanel4Layout.setVerticalGroup(
               jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(jPanel4Layout.createSequentialGroup()
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r21, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel23))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r22, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel24))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r23, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel25))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r24, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel26))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r25, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel27))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r26, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel28))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r27, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel29))
                    .addContainerGap(70, Short.MAX_VALUE))
          );

          r28.setText("0");

          r29.setText("0");

          r30.setText("0");
          r30.addActionListener(new java.awt.event.ActionListener()
          {
               public void actionPerformed(java.awt.event.ActionEvent evt)
               {
                    r30ActionPerformed(evt);
               }
          });

          r31.setText("0");

          jLabel30.setText("$sp");

          jLabel31.setText("$fp");

          jLabel32.setText("$ra");

          jLabel33.setText("PC");

          r32.setText("0");

          jLabel35.setText("$gp");

          lineNumberLabel.setText("0");

          jLabel36.setText("LINE");

          javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
          jPanel5.setLayout(jPanel5Layout);
          jPanel5Layout.setHorizontalGroup(
               jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(jPanel5Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                         .addComponent(jLabel32)
                         .addComponent(jLabel31)
                         .addComponent(jLabel30)
                         .addComponent(jLabel35)
                         .addComponent(jLabel33)
                         .addComponent(jLabel36))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                         .addComponent(r28)
                         .addComponent(r29)
                         .addComponent(r30)
                         .addComponent(r31)
                         .addComponent(r32)
                         .addComponent(lineNumberLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE))
                    .addContainerGap(21, Short.MAX_VALUE))
          );
          jPanel5Layout.setVerticalGroup(
               jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(jPanel5Layout.createSequentialGroup()
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(jLabel35)
                         .addComponent(r28, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(jLabel30)
                         .addComponent(r29, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(jLabel31)
                         .addComponent(r30, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(jLabel32)
                         .addComponent(r31, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(r32, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel33))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(lineNumberLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                         .addComponent(jLabel36))
                    .addContainerGap(99, Short.MAX_VALUE))
          );

          fullExecute.setText("Execute");
          fullExecute.addMouseListener(new java.awt.event.MouseAdapter()
          {
               public void mousePressed(java.awt.event.MouseEvent evt)
               {
                    fullExecuteMousePressed(evt);
               }
          });

          singleLineExecute.setText("Single");
          singleLineExecute.addMouseListener(new java.awt.event.MouseAdapter()
          {
               public void mousePressed(java.awt.event.MouseEvent evt)
               {
                    singleLineExecuteMousePressed(evt);
               }
          });

          reset.setText("Reset");
          reset.addMouseListener(new java.awt.event.MouseAdapter()
          {
               public void mousePressed(java.awt.event.MouseEvent evt)
               {
                    resetMousePressed(evt);
               }
          });

          loadObjectFile.setText("Load OBJ");
          loadObjectFile.addMouseListener(new java.awt.event.MouseAdapter()
          {
               public void mousePressed(java.awt.event.MouseEvent evt)
               {
                    loadObjectFileMousePressed(evt);
               }
          });

          saveObjectFile.setText("Save OBJ");
          saveObjectFile.addMouseListener(new java.awt.event.MouseAdapter()
          {
               public void mousePressed(java.awt.event.MouseEvent evt)
               {
                    saveObjectFileMousePressed(evt);
               }
          });

          javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
          jPanel6.setLayout(jPanel6Layout);
          jPanel6Layout.setHorizontalGroup(
               jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(jPanel6Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                         .addComponent(reset, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                         .addComponent(singleLineExecute, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                         .addComponent(fullExecute, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                         .addComponent(loadObjectFile, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                         .addComponent(saveObjectFile, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
          );
          jPanel6Layout.setVerticalGroup(
               jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(jPanel6Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(singleLineExecute)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(fullExecute)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(reset)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(loadObjectFile)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(saveObjectFile)
                    .addContainerGap(100, Short.MAX_VALUE))
          );

          javax.swing.GroupLayout SimulatorPaneLayout = new javax.swing.GroupLayout(SimulatorPane);
          SimulatorPane.setLayout(SimulatorPaneLayout);
          SimulatorPaneLayout.setHorizontalGroup(
               SimulatorPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, SimulatorPaneLayout.createSequentialGroup()
                    .addGroup(SimulatorPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                         .addGroup(javax.swing.GroupLayout.Alignment.LEADING, SimulatorPaneLayout.createSequentialGroup()
                              .addContainerGap()
                              .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 715, Short.MAX_VALUE))
                         .addGroup(javax.swing.GroupLayout.Alignment.LEADING, SimulatorPaneLayout.createSequentialGroup()
                              .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addGap(18, 18, 18)
                              .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addGap(35, 35, 35)
                              .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                              .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                         .addGroup(javax.swing.GroupLayout.Alignment.LEADING, SimulatorPaneLayout.createSequentialGroup()
                              .addGap(12, 12, 12)
                              .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 715, Short.MAX_VALUE)))
                    .addContainerGap())
          );
          SimulatorPaneLayout.setVerticalGroup(
               SimulatorPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, SimulatorPaneLayout.createSequentialGroup()
                    .addGroup(SimulatorPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                         .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                         .addGroup(SimulatorPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                              .addComponent(jPanel2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                              .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE))
                         .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                         .addComponent(jPanel3, 0, 266, Short.MAX_VALUE)
                         .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
          );

          jTabbedPane1.addTab("Simulator", SimulatorPane);

          jMenu1.setText("File");
          jMenu1.addActionListener(new java.awt.event.ActionListener()
          {
               public void actionPerformed(java.awt.event.ActionEvent evt)
               {
                    jMenu1ActionPerformed(evt);
               }
          });

          menuOpen.setText("Open");
          menuOpen.addMouseListener(new java.awt.event.MouseAdapter()
          {
               public void mouseReleased(java.awt.event.MouseEvent evt)
               {
                    menuOpenMouseReleased(evt);
               }
          });
          menuOpen.addActionListener(new java.awt.event.ActionListener()
          {
               public void actionPerformed(java.awt.event.ActionEvent evt)
               {
                    menuOpenActionPerformed(evt);
               }
          });
          menuOpen.addMenuDragMouseListener(new javax.swing.event.MenuDragMouseListener()
          {
               public void menuDragMouseDragged(javax.swing.event.MenuDragMouseEvent evt)
               {
               }
               public void menuDragMouseEntered(javax.swing.event.MenuDragMouseEvent evt)
               {
               }
               public void menuDragMouseExited(javax.swing.event.MenuDragMouseEvent evt)
               {
               }
               public void menuDragMouseReleased(javax.swing.event.MenuDragMouseEvent evt)
               {
                    menuOpenMenuDragMouseReleased(evt);
               }
          });
          jMenu1.add(menuOpen);

          menuSave.setText("Save");
          menuSave.addMouseListener(new java.awt.event.MouseAdapter()
          {
               public void mouseReleased(java.awt.event.MouseEvent evt)
               {
                    menuSaveMouseReleased(evt);
               }
          });
          menuSave.addMenuDragMouseListener(new javax.swing.event.MenuDragMouseListener()
          {
               public void menuDragMouseDragged(javax.swing.event.MenuDragMouseEvent evt)
               {
               }
               public void menuDragMouseEntered(javax.swing.event.MenuDragMouseEvent evt)
               {
               }
               public void menuDragMouseExited(javax.swing.event.MenuDragMouseEvent evt)
               {
               }
               public void menuDragMouseReleased(javax.swing.event.MenuDragMouseEvent evt)
               {
                    menuSaveMenuDragMouseReleased(evt);
               }
          });
          jMenu1.add(menuSave);

          jMenuBar1.add(jMenu1);

          setJMenuBar(jMenuBar1);

          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
               layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(layout.createSequentialGroup()
                    .addComponent(openButton)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(saveButton)
                    .addGap(547, 547, 547))
               .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 744, Short.MAX_VALUE)
               .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 744, Short.MAX_VALUE)
          );
          layout.setVerticalGroup(
               layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                         .addComponent(openButton)
                         .addComponent(saveButton))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 530, Short.MAX_VALUE))
          );

          pack();
     }// </editor-fold>//GEN-END:initComponents

private void saveObjectFileMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveObjectFileMousePressed
	  int temp;
	  aObject.reset();
	  fileChooser.setFileFilter(new ObjectFilter());
	  temp = fileChooser.showSaveDialog(this);
	  
	  if(temp == fileChooser.APPROVE_OPTION)
	  {
	       FileOutputStream fos;
	       ObjectOutputStream oos;
	       String input;
	       file = fileChooser.getSelectedFile();
	       try
	       {
		    fos = new FileOutputStream(file);
		    oos = new ObjectOutputStream(fos);
		    
		    oos.writeObject(aObject);
		    
		    oos.close();
		    fos.close();
	       }
	       catch(Exception e)
	       {
		    
	       }
	  }
}//GEN-LAST:event_saveObjectFileMousePressed

private void loadObjectFileMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_loadObjectFileMousePressed
     int temp;
	  fileChooser.setFileFilter(new ObjectFilter());
	  temp = fileChooser.showOpenDialog(this);
	  
	  if(temp == fileChooser.APPROVE_OPTION)
	  {
	       FileInputStream fis;
	       ObjectInputStream ois;
	       String input;
	       file = fileChooser.getSelectedFile();
	       try
	       {
		    fis = new FileInputStream(file);
		    ois = new ObjectInputStream(fis);
		    
		    aObject = (Assembled)ois.readObject();
		    
		    ois.close();
		    fis.close();
		    
		    memory = new Storage(aObject.getInitialMemory());
		
		    register = new int[33];
		    register[32] = aObject.getStartPC();
		    register[29] = memory.getStackPointer();
                
		    r32.setText("" + register[32]);
		    r29.setText("" + register[29]);
	       }
	       catch(Exception e)
	       {
		    
	       }
	  }
}//GEN-LAST:event_loadObjectFileMousePressed

private void resetMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resetMousePressed
     memory = new Storage(aObject.getInitialMemory());
     
     aObject.reset();
     
     hi = 0;
     low = 0;
		
     register = new int[33];
     register[32] = aObject.getStartPC();
     register[29] = memory.getStackPointer();
                
     r32.setText("" + register[32]);
     r29.setText("" + register[29]);
}//GEN-LAST:event_resetMousePressed

     private void menuSaveMouseReleased(java.awt.event.MouseEvent evt)//GEN-FIRST:event_menuSaveMouseReleased
     {//GEN-HEADEREND:event_menuSaveMouseReleased
	  int temp;
	  fileChooser.setFileFilter(new AssemblyFilter());
	  temp = fileChooser.showSaveDialog(this);
	  
	  if(temp == fileChooser.APPROVE_OPTION)
	  {
	       //FileOutputStream outFile;
	       //PrintStream out;
	       
	       text = editor.getText();
	       file = fileChooser.getSelectedFile();
	       
	       try
	       {
		    //outFile = new FileOutputStream(file);
		    //out = new PrintStream(outFile);
		    //out.print(text);
		    //out.close();
		    //outFile.close();
		    FileWriter fw = new FileWriter(file);
		    editor.write(fw);
		    fw.close();
	       }
	       catch(Exception e)
	       {
		    
	       }
	  }
     }//GEN-LAST:event_menuSaveMouseReleased

     private void menuSaveMenuDragMouseReleased(javax.swing.event.MenuDragMouseEvent evt)//GEN-FIRST:event_menuSaveMenuDragMouseReleased
     {//GEN-HEADEREND:event_menuSaveMenuDragMouseReleased
	  int temp;
	  fileChooser.setFileFilter(new AssemblyFilter());
	  temp = fileChooser.showSaveDialog(this);
	  
	  if(temp == fileChooser.APPROVE_OPTION)
	  {
	       //FileOutputStream outFile;
	       //PrintStream out;
	       
	       text = editor.getText();
	       file = fileChooser.getSelectedFile();
	       
	       try
	       {
		    //outFile = new FileOutputStream(file);
		    //out = new PrintStream(outFile);
		    //out.print(text);
		    //out.close();
		    //outFile.close();
		    FileWriter fw = new FileWriter(file);
		    editor.write(fw);
		    fw.close();
	       }
	       catch(Exception e)
	       {
		    
	       }
	  }
     }//GEN-LAST:event_menuSaveMenuDragMouseReleased

     private void menuOpenMouseReleased(java.awt.event.MouseEvent evt)//GEN-FIRST:event_menuOpenMouseReleased
     {//GEN-HEADEREND:event_menuOpenMouseReleased
	  int temp;
	  fileChooser.setFileFilter(new AssemblyFilter());
	  temp = fileChooser.showOpenDialog(this);
	  
	  if(temp == fileChooser.APPROVE_OPTION)
	  {
	       FileReader fr;
	       BufferedReader br;
	       String input;
	       file = fileChooser.getSelectedFile();
	       try
	       {
		    fr = new FileReader(file);
		    br = new BufferedReader(fr);
		    /*
		    input = br.readLine();
		    while(input != null)
		    {
			 text = text + input + "\n";
			 input = br.readLine();
		    }
		    
		    br.close();
		    fr.close();
		    
		    editor.setText(text);
		    */
		    editor.read(fr, "assembly file");
		    br.close();
		    fr.close();
	       }
	       catch(Exception e)
	       {
		    
	       }
	  }
     }//GEN-LAST:event_menuOpenMouseReleased

     private void menuOpenMenuDragMouseReleased(javax.swing.event.MenuDragMouseEvent evt)//GEN-FIRST:event_menuOpenMenuDragMouseReleased
     {//GEN-HEADEREND:event_menuOpenMenuDragMouseReleased
	  int temp;
	  fileChooser.setFileFilter(new AssemblyFilter());
	  temp = fileChooser.showOpenDialog(this);
	  
	  if(temp == fileChooser.APPROVE_OPTION)
	  {
	       FileReader fr;
	       BufferedReader br;
	       String input;
	       file = fileChooser.getSelectedFile();
	       try
	       {
		    fr = new FileReader(file);
		    br = new BufferedReader(fr);
		    /*
		    input = br.readLine();
		    while(input != null)
		    {
			 text = text + input + "\n";
			 input = br.readLine();
		    }
		    
		    br.close();
		    fr.close();
		    
		    editor.setText(text);
		    */
		    editor.read(fr, "assembly file");
		    br.close();
		    fr.close();
	       }
	       catch(Exception e)
	       {
		    
	       }
	  }
     }//GEN-LAST:event_menuOpenMenuDragMouseReleased

     private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jMenu1ActionPerformed
     {//GEN-HEADEREND:event_jMenu1ActionPerformed
// TODO add your handling code here:
     }//GEN-LAST:event_jMenu1ActionPerformed

     private void menuOpenActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_menuOpenActionPerformed
     {//GEN-HEADEREND:event_menuOpenActionPerformed
// TODO add your handling code here:
     }//GEN-LAST:event_menuOpenActionPerformed

    private void fullExecuteMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fullExecuteMousePressed
	  execute();
    }//GEN-LAST:event_fullExecuteMousePressed

    private void singleLineExecuteMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_singleLineExecuteMousePressed
        executeLine();
    }//GEN-LAST:event_singleLineExecuteMousePressed

    private void assembleButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_assembleButtonMousePressed
        try
        {
	        aObject = Assembler.assemble(file.getAbsolutePath());
		
		memory = new Storage(aObject.getInitialMemory());
		
		register = new int[33];
		register[32] = aObject.getStartPC();
		register[29] = memory.getStackPointer();
                
                r32.setText("" + register[32]);
                r29.setText("" + register[29]);
		
		errorPane.setText(aObject.getBuildErrors());
        }
        catch(Exception e)
        {
            
        }
    }//GEN-LAST:event_assembleButtonMousePressed

    private void saveButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveButtonMousePressed
         int temp;
	 fileChooser.setFileFilter(new AssemblyFilter());
	  temp = fileChooser.showSaveDialog(this);
	  
	  if(temp == fileChooser.APPROVE_OPTION)
	  {
	       //FileOutputStream outFile;
	       //PrintStream out;
	       
	       text = editor.getText();
	       file = fileChooser.getSelectedFile();
	       try
	       {
		    //outFile = new FileOutputStream(file);
		    //out = new PrintStream(outFile);
		    //out.print(text);
		    //out.close();
		    //outFile.close();
		    FileWriter fw = new FileWriter(file);
		    editor.write(fw);
		    fw.close();
	       }
	       catch(Exception e)
	       {
		    
	       }
	  }
    }//GEN-LAST:event_saveButtonMousePressed

     private void openButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_openButtonMousePressed
        int temp;
	fileChooser.setFileFilter(new AssemblyFilter());
	  temp = fileChooser.showOpenDialog(this);
	  if(temp == fileChooser.APPROVE_OPTION)
	  {
	       FileReader fr;
	       BufferedReader br;
	       String input;
	       file = fileChooser.getSelectedFile();
	       try
	       {
		    fr = new FileReader(file);
		    br = new BufferedReader(fr);
		    /*
		    input = br.readLine();
		    while(input != null)
		    {
			 text = text + input + "\n";
			 input = br.readLine();
		    }
		    
		    br.close();
		    fr.close();
		    
		    editor.setText(text);
		    */
		    editor.read(fr, "assembly file");
		    br.close();
		    fr.close();
	       }
	       catch(Exception e)
	       {
		    
	       }
	  }
     }//GEN-LAST:event_openButtonMousePressed

     private void r30ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_r30ActionPerformed
     {//GEN-HEADEREND:event_r30ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_r30ActionPerformed

     private void r14ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_r14ActionPerformed
     {//GEN-HEADEREND:event_r14ActionPerformed
// TODO add your handling code here:
     }//GEN-LAST:event_r14ActionPerformed

     private void r7ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_r7ActionPerformed
     {//GEN-HEADEREND:event_r7ActionPerformed
// TODO add your handling code here:
     }//GEN-LAST:event_r7ActionPerformed

     private void r4ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_r4ActionPerformed
     {//GEN-HEADEREND:event_r4ActionPerformed
// TODO add your handling code here:
     }//GEN-LAST:event_r4ActionPerformed

     private void openButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_openButtonActionPerformed
     {//GEN-HEADEREND:event_openButtonActionPerformed
// TODO add your handling code here:
     }//GEN-LAST:event_openButtonActionPerformed
     
     /**
      * @param args the command line arguments
      */
     public static void main(String args[])
     {
	  java.awt.EventQueue.invokeLater(new Runnable()
	  {
	       public void run()
	       {
		    new Main().setVisible(true);
	       }
	  });
     }
     
     // Variables declaration - do not modify//GEN-BEGIN:variables
     private javax.swing.JPanel AssemblerPane;
     private javax.swing.JPanel EditorPane;
     private javax.swing.JPanel SimulatorPane;
     private javax.swing.JButton assembleButton;
     private javax.swing.JEditorPane editor;
     private javax.swing.JTextArea errorPane;
     private javax.swing.JFileChooser fileChooser;
     private javax.swing.JButton fullExecute;
     private javax.swing.JLabel jLabel10;
     private javax.swing.JLabel jLabel11;
     private javax.swing.JLabel jLabel12;
     private javax.swing.JLabel jLabel13;
     private javax.swing.JLabel jLabel14;
     private javax.swing.JLabel jLabel15;
     private javax.swing.JLabel jLabel16;
     private javax.swing.JLabel jLabel17;
     private javax.swing.JLabel jLabel18;
     private javax.swing.JLabel jLabel19;
     private javax.swing.JLabel jLabel2;
     private javax.swing.JLabel jLabel20;
     private javax.swing.JLabel jLabel21;
     private javax.swing.JLabel jLabel22;
     private javax.swing.JLabel jLabel23;
     private javax.swing.JLabel jLabel24;
     private javax.swing.JLabel jLabel25;
     private javax.swing.JLabel jLabel26;
     private javax.swing.JLabel jLabel27;
     private javax.swing.JLabel jLabel28;
     private javax.swing.JLabel jLabel29;
     private javax.swing.JLabel jLabel3;
     private javax.swing.JLabel jLabel30;
     private javax.swing.JLabel jLabel31;
     private javax.swing.JLabel jLabel32;
     private javax.swing.JLabel jLabel33;
     private javax.swing.JLabel jLabel35;
     private javax.swing.JLabel jLabel36;
     private javax.swing.JLabel jLabel4;
     private javax.swing.JLabel jLabel5;
     private javax.swing.JLabel jLabel6;
     private javax.swing.JLabel jLabel7;
     private javax.swing.JLabel jLabel8;
     private javax.swing.JLabel jLabel9;
     private javax.swing.JMenu jMenu1;
     private javax.swing.JMenuBar jMenuBar1;
     private javax.swing.JOptionPane jOptionPane1;
     private javax.swing.JPanel jPanel1;
     private javax.swing.JPanel jPanel2;
     private javax.swing.JPanel jPanel3;
     private javax.swing.JPanel jPanel4;
     private javax.swing.JPanel jPanel5;
     private javax.swing.JPanel jPanel6;
     private javax.swing.JScrollPane jScrollPane1;
     private javax.swing.JScrollPane jScrollPane2;
     private javax.swing.JScrollPane jScrollPane3;
     private javax.swing.JSeparator jSeparator1;
     private javax.swing.JSeparator jSeparator2;
     private javax.swing.JTabbedPane jTabbedPane1;
     private javax.swing.JTextField lineNumberLabel;
     private javax.swing.JButton loadObjectFile;
     private javax.swing.JMenuItem menuOpen;
     private javax.swing.JMenuItem menuSave;
     private javax.swing.JButton openButton;
     private javax.swing.JTextArea outputWindow;
     private javax.swing.JTextField r0;
     private javax.swing.JTextField r1;
     private javax.swing.JTextField r10;
     private javax.swing.JTextField r11;
     private javax.swing.JTextField r12;
     private javax.swing.JTextField r13;
     private javax.swing.JTextField r14;
     private javax.swing.JTextField r15;
     private javax.swing.JTextField r16;
     private javax.swing.JTextField r17;
     private javax.swing.JTextField r18;
     private javax.swing.JTextField r19;
     private javax.swing.JTextField r2;
     private javax.swing.JTextField r20;
     private javax.swing.JTextField r21;
     private javax.swing.JTextField r22;
     private javax.swing.JTextField r23;
     private javax.swing.JTextField r24;
     private javax.swing.JTextField r25;
     private javax.swing.JTextField r26;
     private javax.swing.JTextField r27;
     private javax.swing.JTextField r28;
     private javax.swing.JTextField r29;
     private javax.swing.JTextField r3;
     private javax.swing.JTextField r30;
     private javax.swing.JTextField r31;
     private javax.swing.JTextField r32;
     private javax.swing.JTextField r4;
     private javax.swing.JTextField r5;
     private javax.swing.JTextField r6;
     private javax.swing.JTextField r7;
     private javax.swing.JTextField r8;
     private javax.swing.JTextField r9;
     private javax.swing.JButton reset;
     private javax.swing.JButton saveButton;
     private javax.swing.JButton saveObjectFile;
     private javax.swing.JButton singleLineExecute;
     // End of variables declaration//GEN-END:variables

     private javax.swing.JLabel jLabel34;

	private int[] register;
	private int hi;
	private int low;
	private Storage memory;
	private RandomAccessFile raf;
	
	public void updateView(int[] command)
	{
	     r0.setText("" + register[0]);
             r1.setText("" + register[1]);
             r2.setText("" + register[2]);
             r3.setText("" + register[3]);
             r4.setText("" + register[4]);
             r5.setText("" + register[5]);
             r6.setText("" + register[6]);
             r7.setText("" + register[7]);
             r8.setText("" + register[8]);
             r9.setText("" + register[9]);
             r10.setText("" + register[10]);
             r11.setText("" + register[11]);
             r12.setText("" + register[12]);
             r13.setText("" + register[13]);
             r14.setText("" + register[14]);
             r15.setText("" + register[15]);
             r16.setText("" + register[16]);
             r17.setText("" + register[17]);
             r18.setText("" + register[18]);
             r19.setText("" + register[19]);
             r20.setText("" + register[20]);
             r21.setText("" + register[21]);
             r22.setText("" + register[22]);
             r23.setText("" + register[23]);
             r24.setText("" + register[24]);
             r25.setText("" + register[25]);
             r26.setText("" + register[26]);
             r27.setText("" + register[27]);
             r28.setText("" + register[28]);
             r29.setText("" + register[29]);
             r30.setText("" + register[30]);
             r31.setText("" + register[31]);
             r32.setText("" + register[32]);
	     lineNumberLabel.setText("" + command[Array.getLength(command)-1]);
	}

	public void execute()
	{
		int[] command;
		int commandType;
		command = aObject.getLine(register[32]-1);
		
		commandType = command[0];
		
		while(commandType != 5 && commandType != -1)
		{
			switch(commandType)
			{
			case 0:
				rcommand(command);
				break;
			case 1:
				icommand(command);
				break;
			case 2:
				branchcommand(command);
				break;
			case 3:
				l_scommand(command);
				break;
			case 4:
				syscall(command);
				break;
			case 5:
			        movecommand(command);
				break;
			case 6:
			        pseudocommand(command);
				break;
			case 7:
			        pseudoicommand(command);
			}
			++register[32];
                        command = aObject.getLine(register[32] - 1);
                        commandType = command[0];
                        r29.setText("" + register[29]);
		}
                updateView(command);
		
                outputWindow.append("\n\n program has finished executing\n\n");
	}
	public void executeLine()
	{
		int[] command;
		int commandType;
		command = aObject.getLine(register[32]-1);
		
		commandType = command[0];
		
		if(commandType != 5 && commandType != -1)
		{
			switch(commandType)
			{
			case 0:
				rcommand(command);
				break;
			case 1:
				icommand(command);
				break;
			case 2:
				branchcommand(command);
				break;
			case 3:
				l_scommand(command);
				break;
			case 4:
				syscall(command);
				break;
			case 5:
			        movecommand(command);
				break;
			case 6:
			        pseudocommand(command);
				break;
			case 7:
			        pseudoicommand(command);
				break;
			}
			++register[32];
			updateView(command);
		}
	}
	public void executeLine(int pcOverride)
	{
		int[] command;
		int commandType;
		command = aObject.getLine(pcOverride-1);
		
		commandType = command[0];
		
		if(commandType != 5 && commandType != -1)
		{
			switch(commandType)
			{
			case 0:
				rcommand(command);
				break;
			case 1:
				icommand(command);
				break;
			case 2:
				branchcommand(command);
				break;
			case 3:
				l_scommand(command);
				break;
			case 4:
				syscall(command);
				break;
			case 5:
			        movecommand(command);
				break;
			case 6:
			        pseudocommand(command);
				break;
			case 7:
			        pseudoicommand(command);
				break;
			}
			register[32] = pcOverride + 1;
			updateView(command);
		}
	}
	public void syscall(int[] command)
	{
		if(register[2] == 4)//print string
		{
		     outputWindow.append(memory.getString(register[4]));
		}
		else if(register[2] == 1)//print int
		{
		     outputWindow.append("" + register[4]);
		}
		else if(register[2] == 5)//read int
		{
		     //register[2] = Integer.parseInt(inputArea.getText().trim());
		     //register[2] = Integer.parseInt(stdin.readLine().trim());
		     String inputStuff = JOptionPane.showInputDialog("Enter an Integer");
		     register[2] = Integer.parseInt(inputStuff);
		     outputWindow.append("\n");
		}
		else if(register[2] == 2)//print a float $a0 is to print
		{
		    outputWindow.append("" + Float.intBitsToFloat(register[4]));
		}
		else if(register[2] == 3)//print a double $a0 is the first half, $a1 is the second
		{
		     String part1 = Integer.toBinaryString(register[4]);
		     String part2 = Integer.toBinaryString(register[5]);
		     outputWindow.append("" + Double.longBitsToDouble(Long.parseLong(part1 + part2, 2)));
		}
		else if(register[2] == 6)//read a float to $v0
		{
		     String inputStuff = JOptionPane.showInputDialog("Enter a Float");
		     register[2] = Float.floatToRawIntBits(Float.parseFloat(inputStuff));
		     outputWindow.append("\n");
		}
		else if(register[2] == 7)//read double to $v0, $v1
		{
		     String inputStuff = JOptionPane.showInputDialog("Enter a Double");
		     double value = Double.parseDouble(inputStuff);
		     long represented = Double.doubleToRawLongBits(value);
		     String whole = Long.toBinaryString(represented);
		     String string1 = whole.substring(0, 32);
		     String string2 = whole.substring(32);
		     register[2] = Integer.parseInt(string1, 2);
		     register[3] = Integer.parseInt(string2, 2);
		     outputWindow.append("\n");
		}
		else if(register[2] == 8)//read string $a0 is the address, $a1 is max length (-1 is an entire string)
		{
		      String inputStuff = JOptionPane.showInputDialog("Enter a String");
		      if(register[5] != -1)
			 inputStuff = inputStuff.substring(0, register[5]);
		}
		else if(register[2] == 9)//allocates memory from the heap, $a0 is the number of bytes
		{
		     
		}
		else if(register[2] == 10)//exit the program
		{
		     aObject.throwExit();
		}
		else if(register[2] == 11)//print char $a0 is the char
		{
		     outputWindow.append("" + (char)register[4]);
		}
		else if(register[2] == 12)//read char $v0 is where the char is read to
		{
		     String inputStuff = JOptionPane.showInputDialog("Enter a Char");
		     register[2] = (int)inputStuff.charAt(0);
		     outputWindow.append("\n");
		}
		else if(register[2] == 13)//file open, $a0 = full path (0 terminated string w/ no line feed), $a1 = flags, $a2 = permissions(read = 0x0, write = 0x1, read/write = 0x2, append = 0x8, text = 0x4000, binary = 0x8000), $v0 becomes the file descriptor
		{
		     File file = new File(memory.getString(register[4]));
		     try
		     {
		     switch(register[6])
		     {
		     case 0:
			  raf = new RandomAccessFile(file, "r");
			  register[2] = 0;
			  break;
		     case 1:
			  raf = new RandomAccessFile(file, "w");
			  register[2] = 1;
			  break;
		     case 2:
			  raf = new RandomAccessFile(file, "rw");
			  register[2] = 2;
			  break;
		     }
		     }
		     catch(Exception e)
		     {
			  register[2] = -1;
		     }
		}
		else if(register[2] == 14)//file read, $a0 = file descriptor, $a1 = buffer address, $a2 = the amount to read in bytes, $v0 is the amount read from file (-1 error, 0 end of file)
		{
		     int i = 0;
		     int[] readVal = new int[(int)java.lang.Math.ceil((double)register[6]/4.0)];
		     byte[] input = new byte[register[6]];
		     try
		     {
			  register[2] = raf.read(input);
			  while(i < register[6]/4)
			  {
			       readVal[i] = (int)input[4*i];
			       for(int j = 1; j < 4; ++j)
			       {
				   readVal[i] = readVal[i] << 4;
				   readVal[i] = readVal[i] + (int)input[4*i + j];
			       }
			       ++i;
			  }
			  if(i < Array.getLength(readVal))
			  {
			       readVal[i] = (int)input[4*i];
			       for(int j = 4*i + 1; j < register[6]; ++j)
			       {
				    readVal[i] = readVal[i] << 4;
				    readVal[i] = readVal[i] + (int)input[4*i + j];
			       }
			  }
			  for(i = 0; i < Array.getLength(readVal); ++i)
			       memory.setLocation(register[4] + i, readVal[i]);
		     }
		     catch(Exception e)
		     {
			  
		     }
		}
		else if(register[2] == 15)//file write, $a0 = file descripter, $a1 = buffer address, $a2 = amount to write in bytes, $a3 = type (0 = int, 1 = float, 2 = long, 3 = double, 4 = char, 5 = string) $v0 = the amount of data in buffer file (-1 error, 0 end of file)
		{
		     int i = register[5];
		     int end = i + register[6]/4;
		     String string1, string2;
		     try
		     {
		     switch(register[7])
		     {
		     case 0:
			  raf.writeInt(memory.getLocation(i));
			  register[2] = 1;
			  break;
		     case 1:
			  raf.writeFloat(Float.intBitsToFloat(memory.getLocation(i)));
			  register[2] = 2;
			  break;
		     case 2:
			  string1 = Integer.toBinaryString(memory.getLocation(i));
			  string2 = Integer.toBinaryString(memory.getLocation(i + 1));
			  raf.writeLong(Long.parseLong(string1 + string2, 2));
			  register[2] = 3;
			  break;
		     case 3:
			  string1 = Integer.toBinaryString(memory.getLocation(i));
			  string2 = Integer.toBinaryString(memory.getLocation(i + 1));
			  raf.writeDouble(Double.longBitsToDouble(Long.parseLong(string1 + string2, 2)));
			  register[2] = 4;
			  break;
		     case 4:
			  raf.writeChar(memory.getCharAtLocation(i));
			  register[2] = 5;
			  break;
		     case 5:
			  raf.writeChars(memory.getString(i));
			  register[2] = 6;
			  break;
		     }
		     }
		     catch(Exception e)
		     {
			  register[2] = -1;
		     }
		}
		else if(register[2] == 16)//file close, $a0 = file descripter
		{
		     try
		     {
			 raf.close();
		     }
		     catch(Exception e)
		     {
			  
		     }
		}
	}
	//performs all i-type commands
	public void icommand(int[] command)
	{
		int tempone;
		int temptwo;
		
		switch(command[1])
		{
		case 8://addi, add immediate
			register[command[3]] = register[command[2]] + command[4];
			break;
		case 9://addiu, add immediate unsigned
			tempone = register[command[2]];
			temptwo = command[4];
			
			if(tempone < 0)
				tempone *= -1;
			if(temptwo < 0)
				temptwo *= -1;
			
			register[command[3]] = tempone + temptwo;
			break;
			
		case 10://slti
			if(register[command[2]] < command[3])
				register[command[3]] = 1;
			else
				register[command[3]] = 0;
			break;
			
		case 11://sltiu, not implemented as it wasnt needed
			outputWindow.append("sltiu is not yet implemented\n");
			break;
			
		case 12://andi
			register[command[3]] = register[command[2]] & command[4];
			break;
			
		case 13://ori
			register[command[3]] = register[command[2]] | command[4];
			break;
			
		case 14://xori
			register[command[3]] = register[command[2]] ^ command[4];
			break;
			
		case 15://li "15 0 " + memory(tokenizer.nextToken()) + " " + tokenizer.nextToken();
			register[command[3]] = command[4];
			break;
		}
	}
	public void rcommand(int[] command)
	{
		int tempone;
		int temptwo;
		switch(command[6])
		{
		case 4://sllv currently not implemented, as it was not needed
			register[command[4]] = register[command[3]] << register[command[2]];
			break;
		case 6://srlv currently not implemented, as it was not needed
			register[command[4]] = register[command[3]] >> register[command[2]];
			break;
		case 12://syscall preforms the different system calls
			syscall(command);
			break;
		case 32://add adds two registers and stores the result in a register
			register[command[4]] = register[command[2]] + register[command[3]];
			break;
		case 33://addu adds two registers unsigned stores it in a register
			tempone = register[command[2]];
			temptwo = register[command[3]];
			if(tempone < 0)
				tempone *= -1;
			if(temptwo < 0)
				temptwo *= -1;
			register[command[4]] = tempone + temptwo;
			//System.out.println("register " + command[4] + " = " + register[command[4]]);
			break;
		case 34://sub subtracts a register from another, and stores it in a register
			register[command[4]] = register[command[2]] - register[command[3]];
			break;
		case 35://subu same as sub only unsigned
			tempone = register[command[2]];
			temptwo = register[command[3]];
			if(tempone < 0)
				tempone *= -1;
			if(temptwo < 0)
				temptwo *= -1;
			register[command[4]] = tempone - temptwo;
			break;
		case 36://and, not currently implemented as it wasnt needed
			register[command[4]] = register[command[2]] & register[command[3]];
			break;
		case 37://or, not currently implemented as it wasnt needed
			register[command[4]] = register[command[2]] | register[command[3]];
			break;
		case 38://xor, not currently implemented as it wasnt needed
			register[command[4]] = register[command[2]] ^ register[command[3]];
			break;
		case 43://slt, not currently implemented as it wasnt needed
			if(register[command[2]] < register[command[3]])
				register[command[4]] = 1;
			else
				register[command[4]] = 0;
			break;
		}
	}
	public void branchcommand(int[] command)
	{
		int pc = register[32];
		
		switch(command[1])
		{
		case 1://jr performs the jump register command
			pc = register[command[2]];
			break;
			
		case 2://j, performs the jump commmand
			pc = command[2] - 1;
			break;
			
		case 3://jal, performs the jump and link command
			register[31] = pc; //stores the return address in $ra
			pc = command[2] - 1; //creates the new pc
			break;
			
		case 4://beq, performs the branch equal
			if(register[command[2]] == register[command[3]])
				pc = command[4] - 1;
			break;
			
		case 5://bne, performs the branch not equal
			if(register[command[2]] != register[command[3]])
				pc = command[4] - 1;
			break;
			
		case 6://bge, performs the branch greater than or equal
			if(register[command[2]] >= command[3])
				pc = command[4] - 1;
			break;
			
		default://all other branch commands are not currently implemented
			outputWindow.append("misc. branch type not implented\n");
		}
		
		register[32] = pc;
	}
	//performs all the load and store commands
	public void l_scommand(int[] command)
	{
		int temp;
		switch(command[1])
		{
		case 32://la	$a0, str5, load address
			register[command[2]] = command[3] + command[4];
			break;
		case 35://lw	$a0, 0($sp), lowad word
			temp = command[3]/4 + register[command[4]];
			//finds out if the load word command causes an out of bounds error
			if(temp >= memory.getStackPointer())
			{
				//tells the user that the load word has caused
				//an out of bounds error
				outputWindow.append("out of bounds some how, in lw command ");
				
				//indicates to the user what command caused it
				//well in its decimal form anyway
				for(int i = 1; i < 5; ++i)
					outputWindow.append(command[5] + " ");
				outputWindow.append("\n");
				//tells the user what the pc value was
				//this way they can find the error hopefully
				outputWindow.append("The line number is " + command[6] + "\n");
			}
			register[command[2]] = memory.getLocation(temp);
			//System.out.println("register " + command[2] + " = " + register[command[2]]);
			break;
		case 43://sw	$a0, 0($sp), store word
			temp = command[3]/4 + register[command[4]];
				
			//finds out if this causes the program to go out of bounds on its memory
			if(temp >= memory.getStackPointer())
			{
				//tells the user that the load word has caused
				//an out of bounds error
				outputWindow.append("out of bounds some how, in sw command ");
				
				//indicates to the user what command caused it
				//well in its decimal form anyway
				for(int i = 1; i < 5; ++i)
					outputWindow.append(command[i] + " ");
				outputWindow.append("\n");
				//tells the user what the pc value was
				//this way they can find the error hopefully
				outputWindow.append("The line number is " + command[5] + "\n");
			}
			memory.setLocation(temp, register[command[2]]);
			break;
		}
        }
	public void movecommand(int[] command)
	{
	     if(command[1] == 0)
		  register[command[2]] = hi;
	     else
		  register[command[2]] = low;
	}
	public void pseudocommand(int[] command)
	{
	     long temp;
	     String hiValue, lowValue;
	     switch(command[1])
	     {
	     case 0: //div
		  hi = register[command[2]] % register[command[3]];
		  low = register[command[2]] / register[command[3]];
		  break;
	     case 1: //mul
		  temp = (long)register[command[2]] * (long)register[command[3]];
		  register[command[4]] = Integer.parseInt(Long.toBinaryString(temp).substring(32), 2);
		  break;
	     case 2: //mult
		  temp = (long)register[command[2]] * (long)register[command[3]];
		  hi = Integer.parseInt(Long.toBinaryString(temp).substring(0,32), 2);
		  low = Integer.parseInt(Long.toBinaryString(temp).substring(32), 2);
		  break;
	     }
	}
	public void pseudoicommand(int[] command)
	{
	     long temp;
	     String hiValue, lowValue;
	     switch(command[1])
	     {
	     case 0: //div
		  hi = register[command[2]] % command[3];
		  low = register[command[2]] / command[3];
		  break;
	     case 1: //mul
		  temp = (long)register[command[2]] * (long)command[4];
		  register[command[3]] = Integer.parseInt(Long.toBinaryString(temp).substring(32), 2);
		  break;
	     case 2: //mult
		  temp = (long)register[command[2]] * (long)command[3];
		  hi = Integer.parseInt(Long.toBinaryString(temp).substring(0,32), 2);
		  low = Integer.parseInt(Long.toBinaryString(temp).substring(32), 2);
		  break;
	     }
	}
	
	private class AssemblyFilter extends javax.swing.filechooser.FileFilter
	{
	     public boolean accept(File f)
	     {
		  return f.isDirectory() || f.getName().toLowerCase().endsWith(".asm");
	     }
	     public String getDescription()
	     {
		  return ".asm files";
	     }
	}
	
	private class ObjectFilter extends javax.swing.filechooser.FileFilter
	{
	     public boolean accept(File f)
	     {
		  return f.isDirectory() || f.getName().toLowerCase().endsWith(".obj");
	     }
	     public String getDescription()
	     {
		  return ".obj files";
	     }
	}
}
